package test.design_pattern.observer.listener.ordered;

import org.springframework.context.ApplicationEvent;
import org.springframework.context.event.SmartApplicationListener;
import org.springframework.stereotype.Component;
import test.design_pattern.observer.OrderEvent;
import test.design_pattern.observer.OrderService;

//@Component
public class AppPushListener implements SmartApplicationListener {

    @Override
    public boolean supportsEventType(Class<? extends ApplicationEvent> aClass) {
        //只有事件类型是OrderEvent才会响应
        return aClass == OrderEvent.class;
    }

    @Override
    public boolean supportsSourceType(Class<?> aClass) {
        //只有在OrderService发布的的事件时才会响应
        return aClass == OrderService.class;
    }

    @Override
    public void onApplicationEvent(ApplicationEvent applicationEvent) {
        System.out.println("推送app");
    }

    @Override
    public int getOrder() {
        return 2;
    }
}
